<?php


namespace app\api\controller;

use app\common\controller\Api;
use app\common\exception\UploadException;
use app\common\library\Upload;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Request;
use think\Db;


class Live extends Api{


    protected $noNeedLogin = ['signname'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];


    public function submits(){


        $case_id=$this->request->param('case_id');

        $info['data1']=html_entity_decode($this->request->param('data1'));


        // 打印接收到的原始字符串，方便调试

        $info['data2']=html_entity_decode($this->request->param('data2'));
        $info['data3']=html_entity_decode($this->request->param('data3'));


        $info['images']=$this->request->param('images');
        $info['images1']=$this->request->param('images1');
        $info['images2']=$this->request->param('images2');
        $info['images3']=$this->request->param('images3');

//        $info['images4']=$this->request->param('images4');
//        $info['images5']=$this->request->param('images5');
//        $info['images6']=$this->request->param('images6');
//        $info['images7']=$this->request->param('images7');

        $info['allphoto']=$this->request->param('allphoto',0);
        $info['allnum']=$this->request->param('allnum',0);
        $info['allvideo']=$this->request->param('allvideo',0);
        $info['mian']=$this->request->param('mian',0);
        $info['minor']=$this->request->param('minor',0);
        $info['case_id']=$this->request->param('case_id',0);

        $log=Db::name('aa_case_live')->where(['case_id'=>$case_id])->find();

        if ($log){

//            if ($log['status']==1){
//                $this->error('当前无法修改！');
//            }

            Db::name('aa_case_live')->where(['id'=>$log['id']])->update($info);
        }else{
            Db::name('aa_case_live')->data($info)->insert();
        }





        $this->success('操作成功！');

    }

    public function submits2(){


        $case_id=$this->request->param('case_id');


        $info['data4']=($this->request->param('data4'));


//        $info['images']=$this->request->param('images');
//        $info['images1']=$this->request->param('images1');
//        $info['images2']=$this->request->param('images2');
//        $info['images3']=$this->request->param('images3');

        $info['images4']=$this->request->param('images4');
        $info['images5']=$this->request->param('images5');
        $info['images6']=$this->request->param('images6');
        $info['images7']=$this->request->param('images7');

        $info['allphoto1']=$this->request->param('allphoto1');
        $info['allnum1']=$this->request->param('allnum1');
        $info['allvideo1']=$this->request->param('allvideo1');
        $info['mian1']=$this->request->param('mian1');
        $info['minor1']=$this->request->param('minor1');
        $info['case_id']=$this->request->param('case_id');

        $log=Db::name('aa_case_live')->where(['case_id'=>$case_id])->find();

        if ($log){

            if ($log['status']==1){
                $this->error('当前无法修改！');
            }

            Db::name('aa_case_live')->where(['id'=>$log['id']])->update($info);
        }else{
            Db::name('aa_case_live')->data($info)->insert();
        }





        $this->success('操作成功！');

    }

    //详细信息
    public function getinfobyid(){

        $id=$this->request->param('id');

        $info=Db::name('aa_case_live')->where(['case_id'=>$id])->find();

        if (!$info){

            $this->error('无信息！');
        }



        $info['data1']=json_decode($info['data1'],true);
        $info['data2']=json_decode($info['data2'],true);
        $info['data3']=json_decode($info['data3'],true);
        $info['data4']=json_decode($info['data4'],true);

        $info['images']=explode(',',$info['images']);
        $info['images1']=explode(',',$info['images1']);
        $info['images2']=explode(',',$info['images2']);
        $info['images3']=explode(',',$info['images3']);

        $info['images4']=explode(',',$info['images4']);
        $info['images5']=explode(',',$info['images5']);
        $info['images6']=explode(',',$info['images6']);
        $info['images7']=explode(',',$info['images7']);


        $this->success('详细信息！',$info);
    }


    //x修改签名
    public function signname(){

        $id=$this->request->param('id');

        $types=$this->request->param('types');

        $file = $this->request->file('file');
        $upload = new Upload($file);
        $attachment = $upload->upload();

        $imgurl=cdnurl($attachment->url, true);

        $up=[];
        if ($types==1){
            $up['sign1']=$imgurl;
            $up['status']=1;
        }else if($types==2){
            $up['sign2']=$imgurl;
            $up['status']=1;
        }else if($types==3){
            $up['sign3']=$imgurl;
            $up['status']=1;
        }
        else if($types==4){
            $up['sign4']=$imgurl;
            $up['status']=1;
        }
        else if($types==5){
            $up['sign5']=$imgurl;
            $up['status']=1;
        }
        else if($types==6){
            $up['sign6']=$imgurl;
            $up['status']=1;
        }


        Db::name('aa_case_live')->where(['case_id'=>$id])->update($up);

        $this->success("恭喜您,添加成功!");



    }






}